xlv.obj.tab={
	extend:function(){
	},
	implement:function(){
		this.implement('xlv.imp.select');
	},
	create:function(tag){
		var div=document.createElement((tag||'div'));
		div.setAttribute('xlvobject','xlv.obj.tab');
		Element.addClassName(div,'class_tab');
		return div;
	},
	properties:{
		type:'ie', //ie,ff,ns,op,pr
		defaultSelectedIndex:0,
		tabs:null //array
	},
	method:{
		construct:function(){
			var v=this.$V;
			Element.addClassName(this,'class_tab');
			if(this.$P.type)Element.addClassName(this,this.$P.type);
			v.tabs=xlv.util.findDirectChild(this,{id:'xlvid_tabs'});
			if(!v.tabs){
				var content=xlv.util.children(this,{id:'xlvid_tab_content'});
				this.appendChild(v.tabs=document.createElement('div'));
				v.tabs.setAttribute('id','xlvid_tabs');
				for(var i=0;i<content.length;++i)this.addTabContent(content[i]);
			}
			if(this.$P.tabs){
				for(var i=0;i<this.$P.tabs.length;++i){
					this.addTab(this.$P.tabs[i].title);
				}
			}
		},
		initial:function(){
			var tabs=this.getTabs(),index=this.$P.defaultSelectedIndex;
			if(tabs.length>0){
				for(var i=0,n=tabs.length;i<n;++i){
					if(Element.hasClassName(tabs[i],'selected')) index=i;
					else Element.removeClassName(tabs[i],'selected');
				}
				this.selectTab(index);
			}
			this.select_enabled(true);
		},
		styleFor:function(tab,index){
		},
		setTabTitle:function(title,index){
			var tab=this.getTab(index);
			if(tab){
				var c=xlv.util.findChild(tab,{id:'xlvid_tab_content'});
				xlv.util.setElementValue(c,title);
			}
		},
		addTabContent:function(element,index){
			var tab,r,b,c;
			tab=document.createElement('span');
			tab.setAttribute('id', 'xlvid_tab');
			tab.appendChild(r=document.createElement('span'));
			r.setAttribute('id', 'xlvid_tab_right');
			r.appendChild(b=document.createElement('span'));
			b.setAttribute('id', 'xlvid_tab_back');
			if(element.id=='xlvid_tab_content'){
				b.appendChild(element);
			}else{
				b.appendChild(c=document.createElement('span'));
				c.setAttribute('id', 'xlvid_tab_content');
				c.appendChild(element);
			}
			this.$V.tabs.insertBefore(tab,this.getTab(index));
			this.styleFor(tab,this.getTab(tab));
		},
		addTab:function(title,index){
			index=(index>=0)?index:this.getTabs().length;
			var tab,r,b,c;
			tab=document.createElement('span');
			tab.setAttribute('id', 'xlvid_tab');
			tab.appendChild(r=document.createElement('span'));
			r.setAttribute('id', 'xlvid_tab_right');
			r.appendChild(b=document.createElement('span'));
			b.setAttribute('id', 'xlvid_tab_back');
			b.appendChild(c=document.createElement('span'));
			c.setAttribute('id', 'xlvid_tab_content');
			xlv.util.setElementValue(c,title);
			this.$V.tabs.insertBefore(tab,this.getTab(index));
			this.styleFor(tab,this.getTab(tab));
		},
		removeTab:function(index){
			var tab=this.getTab(index);
			if(tab)tab.parentNode.removeChild(tab);
		},
		getTabs:function(){
			return xlv.util.children(this.$V.tabs,{id:'xlvid_tab'});
		},
		getSelectedTab:function(){
			return select_getSelected();
		},
		getSelectedIndex:function(){
			return this.getIndex(this.select_getSelected());
		},
		getIndex:function(tab){
			var tabs=this.getTabs();
			for(var i=0,n=tabs.length;i<n;++i)if(tab==tabs[i])return i;
			return -1;
		},
		getTab:function(index){
			if((typeof index)=='undefined'||index==null) return null;
			var tabs=this.getTabs();
			return (index<0||index>=tabs.length)?null:tabs[index];
		},
		selectTab:function(index){
			var tabs=this.getTabs();
			if((index>=0&&index<tabs.length)&&this.select_selectable(tabs[index]))
				this.select_item(tabs[index]);
		},
		/**select imp**/
		select_selectable:function(item){
			if(xlv.util.isDescendantOf(item, this.$V.tabs)){
				return this.targetElement(item,{id:'xlvid_tab'});
			}
			return null;
		}
	}
};
